<?php
namespace think\template\taglib;

use think\template\TagLib;

use think\Db;
/**
 * 自定义标签类
 */
class Taglibhd extends Taglib{
	//自定义标签
	protected $tags = [
		'topcates' => ['attr'=>'limit','close'=>1],
		];
	//顶级分类标签
	public function tagTopcates($attr,$content)
	{
		$limit=isset($attr['limit'])?$attr['limit']:'';
		$str='<?php ';
		$str .='$where =array("pid" =>0);';
		$str .='$_topcatesResult =  db("category")->where($where)->limit('.$limit.')->select();';
		$str .='foreach ($_topcatesResult as $v): ';
		$str .= '?>';
		$str .=$content; 
		$str .='<?php  endforeach; ?>';

		return $str;
	}
}

?>